<template>
  <BasicDrawer v-bind="$attrs" :loadingText="vform.loadingText" showFooter title="字段信息" width="70%"
               @ok="handleSubmit($refs.xForm, vform, emit, setDrawerProps, changeLoading, closeDrawer)" @register="registerDrawer">
    <vxe-form title-colon ref="xForm" title-align="right" title-width="100" :data="vform.data" :rules="vform.rules">
      <vxe-form-item title="字段名" field="name" :item-render="{}" span="12" title-width="150">
        <template #default="{ data }">
          <vxe-input v-model="data.name" clearable></vxe-input>
        </template>
      </vxe-form-item>
      <vxe-form-item title="注释" field="comet" :item-render="{}" span="12" title-width="150">
        <template #default="{ data }">
          <vxe-input v-model="data.comet" clearable></vxe-input>
        </template>
      </vxe-form-item>
      <vxe-form-item title="备注" field="notes" :item-render="{}" span="24" title-width="150">
        <template #default="{ data }">
          <vxe-input v-model="data.notes" clearable></vxe-input>
        </template>
      </vxe-form-item>

      <vxe-form-item title="创建时间" field="crtim" :item-render="{}" span="12" title-width="150">
        <template #default="{ data }">
          <span>{{ data.crtim }}</span>
        </template>
      </vxe-form-item>
      <vxe-form-item title="创建人" field="upman" :item-render="{}" span="12" title-width="150">
        <template #default="{ data }">
          <span>{{ data.crman?.name }}</span>
        </template>
      </vxe-form-item>
      <vxe-form-item title="修改时间" field="crtim" :item-render="{}" span="12" title-width="150">
        <template #default="{ data }">
          <span>{{ data.uptim }}</span>
        </template>
      </vxe-form-item>
      <vxe-form-item title="修改人" field="upman" :item-render="{}" span="12" title-width="150">
        <template #default="{ data }">
          <span>{{ data.upman?.name }}</span>
        </template>
      </vxe-form-item>
    </vxe-form>
  </BasicDrawer>
</template>
<script lang="ts" setup>
import {ref, computed, reactive, toRaw} from 'vue';
import {BasicDrawer, useDrawerInner} from '/@/components/Drawer';
import {defHttp} from '/@/utils/http/axios';
import {VxeFormPropTypes, VxeFormInstance} from 'vxe-table'
import {handleSubmit} from '/@/comps/vxe/edit';

const emit = defineEmits(['success', 'register']);


const vform = reactive({
  loadingText: '',
  url: '/bi/field/main',
  data: {} as any,
  rules: {
    name: [{required: true, message: '请输入名称'},],
  } as VxeFormPropTypes.Rules
})

const [registerDrawer, {setDrawerProps, changeLoading, closeDrawer}] = useDrawerInner(async (data) => {
  vform.loadingText = "加载中";
  changeLoading(true);
  if (data.record.id) {
    vform.data = await defHttp.get({url: vform.url + '/one/' + data.record.id});
  } else {
    vform.data = data.record;
    vform.data.avtag = true;
  }
  changeLoading(false);
});

</script>
